$().ready(function(){
	zmx.switcher();	
	zmx.createAutoComplete();
});

zmx = {};
zmx.timer = null;
zmx.switcher = function(){
	jQuery('#switch_hander').click(function(){
		jQuery(this).next().slideDown(100);
	}).mouseout(function(){
		zmx.timer = setTimeout(function(){
			jQuery('#switch_hander').next().slideUp(100);
		},200)
	}).mouseenter(function(){
		clearTimeout(zmx.timer);
	}).next().mouseout(function(){
		zmx.timer = setTimeout(function(){
			jQuery('#switch_hander').next().slideUp(100);
		},200)
	}).mouseover(function(){
		clearTimeout(zmx.timer);
	});
	
};

zmx.createAutoComplete = function(){
	jQuery( "#search_auto_complete" ).autocomplete({
            minLength: 0,
            source:zmx.autoSource,
            focus: function( event, ui ) {
                $(this).val(ui.item.label);
                return false;
            },
            select: function( event, ui ) {
				if (ui.item.cate == 'v') { 
					location.href = 'Venues_view_'+ui.item.value+'.html';
				}else{
					location.href = ui.item.link;
				};
                
                return false;
            }
        })
        .data( "autocomplete" )._renderItem = function( ul, item ) {
			if (item.cate == 'a') {
				var sign = '<font color=#EC6000>[资讯]</font>';
			} else if (item.cate == 'v') {
				sign = '<font color=orange>[场馆]</font>';
			} else if (item.cate == 't') {
				sign = '<font color=green>[票品]</font>';
			}
            return $( "<li>" )
                .data( "item.autocomplete", item )
                .append( "<a>" +sign+ item.label + "</a>" )
                .appendTo( ul );
        };
};

zmx.autoSource = function( request, response ) {
	if($.trim(request.term)=='')return;
	jQuery.ajax({
		type : "POST",
		url:  'Index/autocomplete',
		dataType: "json",
		data: {
			keyword: request.term 
		},
		success: function( data ) {
			response( $.map( data.data, function( item ) {
				return {
					label: item.label,
					value: item.id,
					cate:item.cate,
					link:item.link
				};
			}));
		}
	});
};

zmx.tip = function(msg,state){
	jQuery("#flashMessage").remove();
	var tip = '';
	if(state){
		tip+='	<div id="flashMessage">';
        tip+='<p class="bjcg"><span>'+msg+'</span></p>';
    	tip+='</div>';
	}else{
		tip+='	<div id="flashMessage">';
        tip+='<p class="bjsb"><span>'+msg+'</span></p>';
    	tip+='</div>';
	}
	jQuery('body').append(tip);
};
zmx.shineTip = function(){
	var staTar = jQuery(window);
	var width = jQuery(window).width();
	var height = jQuery(window).height();
	jQuery("#flashMessage")
		.css({
			'top':height/2-100+document.body.scrollTop,
			'left':(width-$("#flashMessage").width())/2})
			.fadeIn(800);
	setTimeout("zmx.hideTip()",3000);
};
zmx.hideTip = function(){
		jQuery("#flashMessage").fadeOut(500);
};
